﻿using System;
using System.Globalization;
using System.Windows.Data;

namespace Opds_Viewer.Converter
{
    public class PercentageConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            double val, param;
            var parseValue = Double.TryParse(value.ToString(), out val);
            var parseParam = Double.TryParse(parameter.ToString(), out param);

            if (parseValue && parseParam)
            {
                return val*param;
            }

            return value;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return null;
        }
    }
}
